from django.core.management import BaseCommand
from apps.oaauth.models import OAUser, OADepartment


class Command(BaseCommand):
    def handle(self, *args, **options):
        boarder = OADepartment.objects.get(name="管理员")
        developer = OADepartment.objects.get(name="开发部")
        operator = OADepartment.objects.get(name="运营部")
        saler = OADepartment.objects.get(name="销售部")
        hr = OADepartment.objects.get(name="人事部")
        finance = OADepartment.objects.get(name="财务部")

        # 0-超级用户
        libai = OAUser.objects.create_superuser(email="libai@qq.com", realname="李白", password="123456",
                                                department=boarder)

        dufu = OAUser.objects.create_superuser(email="dufu@qq.com", realname="杜甫", password="123456",
                                               department=boarder)

        # 1-普通用户-开发部leader
        zhangsan = OAUser.objects.create_user(email="zhangsan@qq.com", realname="张三", password="123456",
                                              department=developer)

        # 2-普通用户-运营部leader
        lisi = OAUser.objects.create_user(email="lisi@qq.com", realname="李四", password="123456",
                                          department=operator)

        # 3-普通用户-人事部leader
        wangwu = OAUser.objects.create_user(email="wangwu@qq.com", realname="王五", password="123456",
                                            department=hr)

        # 4-普通用户-财务部leader
        zhaoliu = OAUser.objects.create_user(email="zhaoliu@qq.com", realname="赵六", password="123456",
                                             department=finance)

        # 5-普通用户-销售部leader
        qianqi = OAUser.objects.create_user(email="qianqi@qq.com", realname="钱七", password="123456",
                                            department=saler)

        # 部门指定对应的leader
        # libai 管理:  开发部, 运营部
        # dufu 管理: 销售部, 人事部, 财务部
        # 1. 管理员
        boarder.leader = libai
        boarder.manager = None

        # 2. 开发部
        developer.leader = zhangsan
        developer.manager = libai

        # 3. 运营部
        operator.leader = lisi
        operator.manager = libai

        # 4. 销售部
        saler.leader = qianqi
        saler.manager = dufu

        # 5. 人事部
        hr.leader = wangwu
        hr.manager = dufu

        # 6. 财务部
        finance.leader = zhaoliu
        finance.manager = dufu

        boarder.save()
        developer.save()
        operator.save()
        saler.save()
        hr.save()
        finance.save()

        self.stdout.write("用户数据初始化成功!!!")
# python manage.py inituser